<template>
  <view class="page s-flex-c-s-s">
    <view class="wrap">
      <view class="title">
        {{ details.name }}
      </view>
      <view class="time">
        {{ details.createtime }} | {{ details.consult_bro_col_count }}次收藏
      </view>
      <view class="content" v-html="details.content"></view>
    </view>
    <view class="btm-btns s-flex-r-c-c">
      <view class="sc s-flex-r-c-c">
        <!-- <image
          v-if="details.is_collection"
          class="icon"
          src="../../static/img/index/sc1.png"
          mode=""></image>
        <image
          v-else
          class="icon"
          src="../../static/img/index/sc.png"
          mode=""></image> -->

        <view class="tit s-flex-r-s-c">
          <!-- @click="onShareAppMessage" -->
          <button open-type="share" plain="true" style="width: 242rpx;box-sizing: border-box;">
            <text style="font-size: 34rpx;width: 242rpx;height: 66rpx;">分享</text>
          </button>
        </view>
      </view>
      <view  class="apply s-flex-r-c-c">
		<button open-type="contact" plain="true" style="width: 412rpx;box-sizing: border-box;">
		  <text style="color: #ffffff;font-size: 34rpx;width: 412rpx;height: 66rpx;">咨询</text>
		</button>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref,onMounted, getCurrentInstance } from "vue";
const { proxy } = getCurrentInstance();
import { onLoad } from "@dcloudio/uni-app";
const id = ref("");
const title = ref("");
const details = ref({});
onLoad((e) => {
  id.value = e.id;
  title.value = e.title;
  if (e.title) {
    uni.setNavigationBarTitle({
      title: e.title,
    });
  }
  // addZuJi();
  getProject();
});
onMounted(() => {
  // proxy.path
  proxy.shareObj.path+=`?id=${id.value}`
  console.log('proxy.shareObj.path: ', proxy.shareObj.path)
});
// 获取项目详情
function getProject(e) {
  proxy
    .$request({
      url: "api/consult/consultDetails",
      header: "application/x-www-form-urlencoded",
      data: { id: id.value },
    })
    .then((res) => {
      details.value = res.data.details;
    });
}
// 收藏
function collection() {
  proxy
    .$request({
      url: "api/consult/consultBroCol",
      header: "application/x-www-form-urlencoded",
      data: { id: id.value, type: 1 },
    })
    .then((res) => {
      if (res.code == 0) {
        return proxy.$toast(res.msg);
      } else {
        if (details.value.is_collection == 1) {
          proxy.$toast("取消收藏成功");
        } else {
          proxy.$toast("收藏成功");
        }
        getProject();
      }
    });
}
// 足迹
function addZuJi() {
  proxy
    .$request({
      url: "api/consult/consultBroCol",
      header: "application/x-www-form-urlencoded",
      //type 1收藏2浏览
      data: { id: id.value, type: 2 },
    })
    .then((res) => {
      if (res.code == 0) {
        return proxy.$toast(res.msg);
      }
    });
}

//分享到朋友圈
function onShareTimeline(res) {
  return {
    title: "文本",
    type: 0,
    summary: "",
  };
}
function onShareAppMessage(res) {
  var insg = uni.getStorageSync("userinfo");
  if (res.from === "button") {
    // 来自页面内分享按钮
    console.log(res.target);
  }
  return {
    title: "项目详情", //分享的名称
    path: "/pages/index/index?sourceUserId=" + insg.id, // 点击链接进入的页面
    mpId: "wxd84a409b5e9d720a", //此处配置微信小程序的AppId
  };
}
</script>

<style lang="scss" scoped>
.wrap {
  padding-bottom: 98rpx;
  .title {
    font-weight: bold;
    font-size: 44rpx;
    color: #333333;
    line-height: 64rpx;
    padding: 20rpx 32rpx;
  }
  .time {
    font-weight: 400;
    font-size: 24rpx;
    color: #666666;
    line-height: 44rpx;
    padding: 0rpx 32rpx;
    padding-bottom: 16rpx;
    border-bottom: 2rpx solid #f8f8f8;
  }
  .content {
    padding: 38rpx 32rpx;
  }
}
.btm-btns {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 750rpx;
  height: 98rpx;
  background: #ffffff;
  border-radius: 0rpx 0rpx 0rpx 0rpx;
  button {
    background: none !important;
    border: none !important;
    color: #ff7139;
  }
  button[plain] {
    border: 0;
  }
  .sc {
    width: 242rpx;
    height: 66rpx;
    border-radius: 16rpx 16rpx 16rpx 16rpx;
    border: 2rpx solid #ff7139;
    margin-right: 32rpx;
    .icon {
      width: 32rpx;
      height: 32rpx;
      margin-right: 8rpx;
    }
    .tit {
      font-weight: 500;
      font-size: 32rpx;
      color: #ff7139;
      line-height: 44rpx;
    }
  }
  .apply {
    width: 412rpx;
    height: 66rpx;
    background: #ff7139;
    border-radius: 16rpx 16rpx 16rpx 16rpx;
	color: #ffffff;
    .icon {
      width: 36rpx;
      height: 36rpx;
      margin-right: 8rpx;
    }
    .tit {
      font-weight: 500;
      font-size: 32rpx;
      color: #ffffff;
      line-height: 44rpx;
    }
  }
}
</style>
